package com.app.news;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.app.news.util.MyHelper;
import com.app.news.util.SpSave;

public class Main2Activity extends AppCompatActivity {

    private EditText usernameEd;
    private EditText passwordEd;
    private Button loginBtn;
    private TextView settingBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_index);
        initView();
        initEvent();
    }
    private void initView(){
        usernameEd = findViewById(R.id.username_et);
        passwordEd = findViewById(R.id.password_et);
        loginBtn = findViewById(R.id.login_btn);
        settingBtn = findViewById(R.id.setting_tv);
    }
    private void initData(){
        String usernameStr=usernameEd.getText().toString()+"";
        String passwordStr=passwordEd.getText().toString()+"";
        SpSave.saveString(Main2Activity.this,"username",usernameStr);
        SpSave.saveString(Main2Activity.this,"password",passwordStr);
        MyHelper myHelper=new MyHelper(Main2Activity.this);
        myHelper.insert(Main2Activity.this,usernameStr,passwordStr);
    }
    private void initEvent(){
        loginBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initData();
                Intent intent=new Intent(Main2Activity.this,TwoActivity.class);
                startActivity(intent);
            }
        });
        settingBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(Main2Activity.this, AboutActivity.class);
                startActivity(intent);
            }
        });
    }
}
